home *** CD-ROM | disk | FTP | other *** search
- Path: news.cc.uic.edu!usenet
- From: Qi Zeng <zeng@sunphy1.phy.uic.edu>
- Newsgroups: comp.lang.c
- Subject: Re: variable length string
- Date: 6 Feb 1996 04:43:45 GMT
- Organization: University of Illinois at Chicago
- Message-ID: <4f6ma1$613e@tigger.cc.uic.edu>
- References: <4f5s97$8sho@tigger.cc.uic.edu> <9602052314.AA18664@dxmint.cern.ch>
- NNTP-Posting-Host: sunphy1.phy.uic.edu
-
- Dan Pop <danpop@mail.cern.ch> wrote:
- >
- > Qi Zeng <zeng@sunphy1.phy.uic.edu> writes:
- > > >Suppose you want to read from stdin a string, but you do not know how
- > >long it will be. You have to assign the string to some char*,
- >
- > Use fgets with a reasonably sized buffer. After reading the string,
- > use strlen to find out its real length, malloc the right amount of memory
- > and copy the string there (dropping the terminating '\n').
- > > Dan
-
- Thanks.
-
- And yes, it is a way to do that. But how to deal with the space you
-
- malloced? Say you return a char *, which points to the space you jsut
-
- malloced. When do you free them?
-
- Qi Zeng
-
-
-